#include <pthread.h>
#include "common.h"
#ifndef SERVER_H
	#define SERVER_H

typedef struct msg_error
{
	int  error_level;
	char *error_code;
	char *error_cmd;
	char *error_time;
}MSG_ERROR;

typedef struct sock_pack
{
	PK_COMMON  package;
	int sock_word;
}SOCK_PACK;

typedef struct thread_pool
{
	pthread_t tid;
	int number;
}TIDPOOL;

typedef struct log_data
{
	int flag;
	char *date;
	int err_code;
	char *err_display;
}LOG_DATA;

typedef struct log_list
{
	LOG_DATA  data;
	struct log_list *next;
}LOG_LIST;

typedef struct ini_settings
{
	struct sockaddr_in ipaddr_port;
	int                connect_max;
	char               *usrname;
	char               *psd;
	char		   *file_path;
	int		   log_level;
}INI_SETTINGS;

INI_SETTINGS setting;

int server_init();

ssize_t readline(int fd,void *buf,int size);

ssize_t writeline(int fd,const void *buf,int size);

int log_info(MSG_ERROR error);

int log_warning(MSG_ERROR error);

int log_error(MSG_ERROR error);

int log_fatal_error(MSG_ERROR error);

void *thread_fun(void *arg);

void *thread_iflive_fun(void *arg);

int do_request(PK_COMMON pack,int sock,MSG_ERROR *error,LOG_LIST **linklist);

int do_error(PK_COMMON *cm_pack,MSG_ERROR *error,LOG_LIST **linklist);

LOG_LIST *loglist_destroy(LOG_LIST *list);

//int send_packet(int sockfd,PK_COMMON *pack,int pack_size);

//int recv_packet(int sockfd,PK_COMMON *pack,int pack_size);

static void sig_routine();

static void debug();

void trace();

#endif
